package js.android.nateroidbeta;

import java.util.ArrayList;

import rath.nateon.NateUser;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class NateroidBeta extends Activity {
    /** Called when the activity is first created. */

	private EditText etUsername;
	private EditText etPassword;
	private Button btnLogin;
	private Button btnCancel;
	private TextView lblResult;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		NateOnSingleton.SetStatus(UIStatus.OnLogin);
		
        // Get the EditText and Button References
        etUsername = (EditText)findViewById(R.id.username);
        etPassword = (EditText)findViewById(R.id.password);
        btnLogin = (Button)findViewById(R.id.login_button);
        btnCancel = (Button)findViewById(R.id.cancel_button);
        lblResult = (TextView)findViewById(R.id.result);
        
        //Set Click Listener
        btnLogin.setOnClickListener(new OnClickListener(){
        	@Override
        	public void onClick(View v){
        		String username = etUsername.getText().toString();
        		String password = etPassword.getText().toString();
        		
        		NateOnSingleton.SetUserID(username, password);
        		
        		if(NateOnSingleton.Login() == true)
        		{
//        			finish();
        			Intent myIntent = new Intent(v.getContext(), FriendList.class);
	    			startActivityForResult(myIntent,0);
        		}
        		else
        		{
        			AlertDialog.Builder msg = new AlertDialog.Builder(v.getContext());
					msg.setTitle("Debug");
					msg.setMessage("Login Fail, Try again");
					msg.setPositiveButton("OK", null);
					msg.show();
	        		etUsername.setText("");
	        		etPassword.setText("");
	        		// error message
        		}
        	}
        });
        
        btnCancel.setOnClickListener(new OnClickListener(){
        	@Override
        	public void onClick(View v){
        		finish();
        		
        	}
        });

   	
    	/*
    	setContentView(R.layout.main);
	    	
	    	Button Start = (Button) findViewById(R.id.start_button);
	    	
	    	Start.setOnClickListener(new View.OnClickListener() {
	    		public void onClick(View view){
//	    			Intent myIntent = new Intent(view.getContext(), LoginScreen.class);
	    			Intent myIntent = new Intent(view.getContext(), List.class);
	    			startActivityForResult(myIntent,0);
	    		}
	    	});
*/
    	/*
    	Intent myIntent = new Intent(view.getContext(), Login.class);
    	StartActivityForResult(myIntent,0);
    	  */
    	/*
    	NateOnSingleton nateon = NateOnSingleton.getInstance();
    	
		ArrayList <String> BUDDIES = new ArrayList<String>();
						
		ArrayList<NateUser> friendsList = (ArrayList<NateUser>)nateon.getFriendsList();

		for(int i = 0; i < friendsList.size(); i++)
		{
			BUDDIES.add(friendsList.get(i).getName());
		}
			/*
    	setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, BUDDIES));
    	getListView().setTextFilterEnabled(true);
    	*/
    	
//        setContentView(R.layout.main);
    }
}

